﻿package mortal.game.view.guild.otherpanel
{
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.guild.cellrender.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildApplyListPanel extends GuildOtherBasePanel
    {
        private var _pageSelecter:PageSelecter;
        private var _btnRejectAll:GButton;
        private var _btnAgreeAll:GButton;
        private var _applyList:GTileList;
        private static const PAGE_MEMBER_COUNT:int = 10;
        private static var _instance:GuildApplyListPanel = null;

        public function GuildApplyListPanel(param1:ILayer = null)
        {
            super(param1);
            setSize(550, 402);
            title = "" + Language.getString(71139);
            return;
        }// end function

        override public function layoutUI() : void
        {
            UIFactory.bg(12, 30, 537, 26, this, ImagesConst.RegionTitleBg);
            UIFactory.gTextField(Language.getString(60066), 54, 34, 54, 20, this);
            UIFactory.gTextField(Language.getString(60027), 180, 34, 30, 20, this);
            UIFactory.gTextField(Language.getString(60067), 268, 34, 30, 20, this);
            UIFactory.gTextField(Language.getString(60036), 354, 34, 45, 20, this);
            UIFactory.gTextField(Language.getString(60033), 473, 34, 30, 20, this);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = "center";
            this._pageSelecter = UIFactory.pageSelecter(217, 375, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, _loc_1);
            this._pageSelecter.maxPage = 3;
            this._pageSelecter.currentPage = 1;
            this._pageSelecter.pageTextBoxSize = 45;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._btnAgreeAll = UIFactory.gButton(Language.getString(60068), 375, 373, 64, 24, this);
            this._btnRejectAll = UIFactory.gButton(Language.getString(60069), 449, 373, 64, 24, this);
            this._applyList = UIFactory.tileList(13, 58, 530, 306, this);
            this._applyList.rowHeight = 30.5;
            this._applyList.columnWidth = 668;
            this._applyList.horizontalGap = 1;
            this._applyList.verticalGap = 0.5;
            this._applyList.setStyle("cellRenderer", GuildApplyListCellRenderer);
            return;
        }// end function

        override public function update() : void
        {
            var _loc_5:int = 0;
            var _loc_6:SMiniPlayer = null;
            if (!isLoadComplete)
            {
                return;
            }
            var _loc_1:* = Cache.instance.guild.selfGuildInfo;
            if (_loc_1.applyMemberList == null)
            {
                return;
            }
            _loc_1.applyMemberList.sort(this.applyMemberSortFunc);
            this._pageSelecter.maxPage = Math.ceil(_loc_1.applyMemberList.length / PAGE_MEMBER_COUNT);
            var _loc_2:* = (this._pageSelecter.currentPage - 1) * PAGE_MEMBER_COUNT;
            var _loc_3:* = new DataProvider();
            var _loc_4:int = 0;
            while (_loc_4 < PAGE_MEMBER_COUNT)
            {
                
                _loc_5 = _loc_2 + _loc_4;
                if (_loc_5 >= _loc_1.applyMemberList.length)
                {
                    break;
                }
                _loc_6 = _loc_1.applyMemberList[_loc_5];
                _loc_3.addItem(_loc_6);
                _loc_4++;
            }
            this._applyList.dataProvider = _loc_3;
            this._applyList.drawNow();
            return;
        }// end function

        override public function onMouseClick(event:MouseEvent) : void
        {
            var _loc_2:Object = null;
            switch(event.target)
            {
                case this._btnRejectAll:
                {
                    _loc_2 = new Object();
                    _loc_2.playerID = 0;
                    _loc_2.agree = false;
                    _loc_2.handleAll = true;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_DEAL_APPLY, _loc_2));
                    break;
                }
                case this._btnAgreeAll:
                {
                    _loc_2 = new Object();
                    _loc_2.playerID = 0;
                    _loc_2.agree = true;
                    _loc_2.handleAll = true;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_DEAL_APPLY, _loc_2));
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.update();
            return;
        }// end function

        private function applyMemberSortFunc(param1:SMiniPlayer, param2:SMiniPlayer) : Number
        {
            if (param1.online && !param2.online)
            {
                return -1;
            }
            if (!param1.online && param2.online)
            {
                return 1;
            }
            return 0;
        }// end function

        public static function get instance() : GuildApplyListPanel
        {
            if (!_instance)
            {
                _instance = new GuildApplyListPanel;
            }
            return _instance;
        }// end function

    }
}
